<template>
  <el-table :data="list" style="width: 100%">
    <el-table-column fixed prop="id" label="ID" width="150" />
    <el-table-column prop="name" label="姓名" width="120" />
    <el-table-column prop="place" label="籍贯" width="120" />
    <el-table-column fixed="right" label="操作" width="120">
      <template v-slot="{row}">
        <el-button link type="primary" size="small" @click="del(row.id)"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import axios from 'axios'

// 定义数据 table数据
const list = ref([])
// 获取接口数据
const getList = async () => {
  const res = await axios.get('/list')
  console.log(res)
  list.value =res.data
}
onMounted(() => {
  getList()
})

// 删除功能
const del = async (id) => {
  await axios.delete(`/del?id=${id}`)
  getList()
}
</script>
